import time
from unittest import TestCase
from appium import webdriver
from FinanceData import FinanceData
from FinanceOperation import FinanceOperation
from ddt import ddt, data, unpack

@ddt
class TestLoan(TestCase):
    finance_data = FinanceData()
    url = 'http://127.0.0.1:4723/wd/hub'
    param = {
        "deviceName": "8HJ76H49KJQKM7IF",
        "platformName": "Android",
        "platformVersion": "13",
        "appPackage": "com.duxiaoman.wallet",
        "appActivity": "com.duxiaoman.wallet.home.SplashActivity"
    }

    @data(*finance_data.finance_data)
    @unpack
    def test_loan(self, expect):
        time.sleep(5)
        driver = webdriver.Remote(self.url, self.param)
        finance_operation = FinanceOperation()
        result = finance_operation.finance(driver)
        if result != expect:
            driver.save_screenshot('借款失败！' + '.jpg')
        else:
            print('通过')
        self.assertEqual(result, expect)
